# -*- coding: utf-8 -*-
# 异常错误处理 错误都是从BaseException进行派生的

import io
import sys
import logging
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')

logging.basicConfig(level=logging.INFO)

try:
	print('try...')
	r = 10 / int('a')
	print('result: ',r)
except ValueError as e:
	print('ValueError: ',e)
except ZeroDivisionError as e:
	print('ZeroDivisionError: ',e)
else:
	print('no error!')
finally:
	print('finally...')
print('End')

def foo(s):
	return 10 / int(s)

def bar(s):
	return foo(s) * 2
def main():
	try:
		bar('0')
	except Exception as e:
		logging.exception(e)
main()
print('End')

class FooError(ValueError):
	pass

def foo(s):
	n = int(s)
	if n==0:
		raise FooError('invalid value: %s' % s)
	return 10 / n

# foo('0')

def bar():
	try:
		foo('0')
	except ValueError as e:
		print('ValueError!')
		raise
bar()